package com.nkzy.mapper;

import com.nkzy.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

    @Insert("INSERT INTO user(username, password, phone, info, status, balance, create_time, update_time) " +
            "VALUES(#{username}, #{password}, #{phone}, #{info}, #{status}, #{balance}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertUser(User user);

    @Update("UPDATE user SET username=#{username}, password=#{password}, phone=#{phone}, info=#{info}, " +
            "status=#{status}, balance=#{balance}, update_time=#{updateTime} WHERE id=#{id}")
    void updateUser(User user);

    @Delete("DELETE FROM user WHERE id=#{id}")
    void deleteUser(Long id);

    @Select("SELECT * FROM user WHERE id=#{id}")
    User selectUserById(Long id);

    @Select("SELECT * FROM user")
    List<User> selectAllUsers();

    @Select("<script>" +
            "SELECT * FROM user WHERE id IN " +
            "<foreach item='id' index='index' collection='list' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    List<User> selectUsersByIds(List<Long> ids);
}